﻿//++
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
// Module Name:
//
//    NotificationCustomChannelTest.cs
//
// Abstract:
//    
//    Unit tests for custom channels.
//
//--

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.EnhancedReminders.Common.UnitTests
{
    /// <summary>
    ///This is a test class for NotificationCustomChannelTest and is intended
    ///to contain all NotificationCustomChannelTest Unit Tests
    ///</summary>
    [TestClass()]
    public class NotificationCustomChannelTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        /// <summary>
        ///A test for NotificationCustomChannel Constructor
        ///</summary>
        [TestMethod()]
        public void NotificationCustomChannelConstructorTest()
        {
            NotificationCustomChannel channel = new NotificationCustomChannel();
            Assert.IsTrue(IsValidCustomId(channel.Id), "Id");

            channel = new NotificationCustomChannel(NotificationChannelType.SMS, "name", "value");
            Assert.AreEqual(NotificationChannelType.SMS, channel.NotificationChannelType, "NotificationChannelType");
            Assert.IsTrue(IsValidCustomId(channel.Id), "Id2");
        }

        /// <summary>
        ///A test for NotificationCustomChannel Copy() method.
        ///</summary>
        [TestMethod()]
        public void VerifyCopyMethod()
        {
            // Create a custom channel and downcast to a NotificationChannel to verify correct Copy() is invoked.
            NotificationChannel originalChannel = new NotificationCustomChannel(NotificationChannelType.Phone, "name", "value");

            NotificationChannel copyChannel = originalChannel.Copy();

            Assert.IsTrue(copyChannel.GetType() == typeof(NotificationCustomChannel), "Expected custom channel");
            Assert.AreEqual(originalChannel.Id, copyChannel.Id, "Id");
            Assert.AreEqual(originalChannel.NotificationChannelType, copyChannel.NotificationChannelType, "NotificationChannelType");
            Assert.AreEqual(originalChannel.UserDefinedName, copyChannel.UserDefinedName, "UserDefinedName");
            Assert.AreEqual(originalChannel.UserDefinedValue, copyChannel.UserDefinedValue, "UserDefinedValue");
        }

        /// <summary>
        /// Helper method to verify that the channel ID is valid for a custom channel.
        /// </summary>
        private static bool IsValidCustomId(Guid id)
        {
            return id != Guid.Empty &&
                   !(id == NotificationChannel.CommunicatorId ||
                     id == NotificationChannel.HomePhoneId ||
                     id == NotificationChannel.MobilePhoneId ||
                     id == NotificationChannel.WorkPhoneId ||
                     id == NotificationChannel.OtherPhoneId);
        }
    }
}
